# 新闻详情模块的蓝图

from flask import Blueprint, session, request, url_for, redirect

# 创建蓝图对象
admin_blu = Blueprint("admin", __name__)

from . import views


@admin_blu.before_request
def check_admin():
    if request.url.endswith(url_for('admin.login')):
        # if 不是管理员，那么直接跳转到主页
        is_admin = session.get("is_admin", False)
        user_id = session.get("user_id")
        # if not is_admin and 当前访问的url不是管理登录页:
        if not is_admin and user_id:
            return redirect('/')
